package com.libui.navigatonbar

import com.libbase.MapCodable
import com.libui.utils.ColorUtils

data class StyleData(val color: Int?, val fontData: FontData?) : MapCodable {
    companion object {
        fun create(map: Map<String, Any>): StyleData {
            val color = (map["map"] as? String)?.let { ColorUtils.toColor(it) }
            val fontData = (map["font"] ?: map["fontSize"])?.let { FontData.create(it) }

            return StyleData(color, fontData)
        }
    }

    override fun toMap(): Map<String, Any> {
        val map = mutableMapOf<String, Any>()

        if (color != null) {
            map["color"] = ColorUtils.toHexString(color)
        }

        if (fontData != null) {
            map["font"] = fontData.toMap()
        }

        return map
    }
}